/*
 * CS 567 GUI - Homework 3 - Problem 2 of 2
 * Jason Frank
 * Due 2/27/11
 */

package textselection;

import javax.swing.*;

/*  This app displays lines of strings provided on the command line, and then attempts
 *  to display a cursor-like line at the (x,y) point of a mouse click (before the char).
 *  Other keyboard events are also incorporated.
 *  And invocation would look like:
 *    unix> java <prog-name> <string-point-size>  "String one" "Sring two" ...
 */
public class selectText {

  // constructor
  public selectText(int strPointSize, String strs[]) {

    // Get a Model
    TextSelectionModel model = new TextSelectionModel(strPointSize, strs);

    // Get new Views
    JComponent textView = new TextView(model); 
  
    JFrame window = new JFrame("Select Text Application");
    // Add all views to the content pane
    window.getContentPane().add(textView);
    
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.pack();
    window.setVisible(true);
  } ////////// end constructor ////


  /*
   */
  public static void main(String[] args) {

    if(args.length < 2 ) { usage(); }

    // doing the partseInt here verifies int args right away (throws exception if not int)
    final int strPointSize = Integer.parseInt(args[0]);

    final String strs[] = new String[args.length - 1];
    // Copy strings from args array into strs array for readability
    //          src array, srcPos, dest array, destPos, length
    System.arraycopy(args, 1, strs, 0, (args.length - 1) );

    // standard code for making all drawing occur in the event thread rather than main thread
    java.awt.EventQueue.invokeLater(new Runnable(){
      public void run() {
        selectText obj = new selectText(strPointSize, strs);
      }
    });

  }  /// end main() ////////////

  private static void usage() {
    System.err.println("\nUsage:  java <prog-name> <string-point-size> "
                     + " \"String one\" \"Sring two\" <...other strings>\n");
    System.exit(1);
  }

} //////////////////// end class selectText ////////////////
